<template>
	<view class="body"> 
		<view class="list">
			<view class="listBor" v-for="(item,index) in shopListes" @tap="tabpar(item)" :key="index">
				<view class="listBorTop">
					<image :src='item.img' class="img"></image>
				</view>
				<view class="listBorBot_one nowrap">
					{{item.title}}
				</view>
				<view class="listBorBot_two">
					<view class="num">￥{{item.price/100}} </view>
					<view class="money">已售{{item.sales}}件 </view>
				</view>
			</view>
			<view class="load">
				{{loadText}}
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				textOne: true,
				status: 1,
				shopListes: [],
				shopName: '',
				loadText: '没有更多数据了',
				// tab切换
				currentTab: 0,
				current:0,
				oId : '',
			}
		},
		onShow(){
			if (uni.getStorageSync('accessToken') == '') {
				uni.showModal({
					title: '登录提示',
					content: '您尚未登录，是否立即登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '../login/login'
							})
							return
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			}
		},
		onLoad(options) {
			console.log(options)
			if (options.fid != null) {
				this.oId = options.fid
				console.log(this.oId)
					uni.request({
						url: 'http://192.168.1.84:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=&pageSize=&categoryId='+this.oId+'&orderBy=&isAsc=&title=',
						success: res => {
							console.log(res)
							this.shopListes = res.data.data.items
						}
					})
			} else if(options.goods != null){
				var list = JSON.parse(options.goods)
				this.shopName = options.name
				this.shopListes = list
				this.selected()
			}else if (options.data != null){
				console.log(options.data)
				this.shopName = options.data
				this.selected()
			}else if(options.iid != null){
				var list = JSON.parse(options.iid)
				this.oId = list
				console.log(this.oId)
				this.selected()
			}else if (options.url != null){
				var list = JSON.parse(options.url)
				this.oId = Number(list)
				this.selected()
			}else if (options.pages != null){
				var list = JSON.parse(options.pages)
				this.oId = Number(list)
				console.log(this.oId)
				this.selected()
			}
		},
		onPullDownRefresh() {
			console.log('refresh');
			var that = this
			this.loadText = "上拉显示更多数据"
			setTimeout(function() {
				that.loadText = "没有更多数据了"
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			//销量优先
			selected(){	
				let that = this
				   uni.request({
				   	url: 'http://192.168.1.84:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=1&pageSize=100000&categoryId='+this.oId+'&orderBy=sales&isAsc=&title='+this.shopName+'',
				   	success: res => {
						console.log(res,'555')
				   		that.shopListes = res.data.data.items
				   	},
				   })
				   this.currentTab = 0
			  },
			  selected1(){ 
				  //价格
				 var that = this
				 that.textOne = !that.textOne
				 uni.request({
				 	url: 'http://192.168.1.84:8081/m.api?_gp=goods&_mt=getGoodsPage&pageNo=&pageSize=&categoryId='+this.oId+'&orderBy=price&isAsc='+this.textOne+'&title='+this.shopName+'',
				 	success: res => {
						console.log(res,'666')
				 		that.shopListes =res.data.data.items
				 	},
				 }),
				 this.currentTab = 1
				 if (this.current == 0) {
				 	this.current = 1
				 } else{
				 	this.current = 0
				 }
			  },
			swichNav: function(e) {
				console.log(e);
				var that = this;
				if (this.currentTab === e.target.dataset.current) {
					return false;
				} else {
					this.currentTab = e.target.dataset.current
				}
			},
			tabpar(item){
				let id = item.id
				uni.navigateTo({
					url: '/pages/details/product?dataset='+id+'&num=1',
				})
			}
		}


	};
</script>
<style>
	.icon {display: flex;
		position: absolute;top:2rpx;left: 212rpx;font-size: 30rpx;
		align-items: center
	}
	.icon-paixujiantouxia{position: absolute;top: 4rpx;}
	.bcoor{color: red;}
	.nav {
		width: 100%;
		height: 100rpx;
		display: flex;
		flex-direction: row;
		background-color: #FFFFFF;
		box-shadow: 0 1px 5px rgb(0 0 0 / 6%);
	}

	.lefat {
		line-height: 100rpx;
		text-align: center;
		flex: 1;
		color: #000;
		font-weight: bold;
		font-size: 28rpx;
	}

	.num {
		float: left;
		color: #FA436A;
		font-size: 30rpx;
		line-height: 40rpx;
	}

	.money {
		float: right;
		color: #909399;
		font-size: 23rpx;
		line-height: 48rpx;
	}

	.img {
		width: 100%;
		height: 100%;
	}

	.righta {
		line-height: 100rpx;
		text-align: center;
		flex: 1;
		position: relative;
		font-weight: bold;
		font-size: 28rpx;
	}

	.active {
		border-bottom: 4rpx solid #fc5558;
		color: #fc5558;
		padding: 26rpx;
	}

	.colora {
		color: #fc5558
	}

	.show {
		display: block;
		text-align: center;
		line-height: 200rpx;
	}

	.hidden {
		display: none;
		text-align: center;
		line-height: 200px;
	}

	.list {
		width: 100%;
		margin: auto;
		margin-top: 15rpx;
	}

	.listBor {
		width: 350rpx;
		height: 420rpx;
		float: left;
		margin-left: 19rpx;
	}

	.listBorTop {
		width: 100%;
		height: 310rpx;
		float: left;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.listBorBot_one {
		width: 100%;
		height: 40rpx;
		float: left;
		line-height: 40rpx;
		font-size: 30rpx;
	}

	.listBorBot_two {
		width: 100%;
		height: 40rpx;
		float: left;

	}

	.nowrap {
		white-space: nowrap;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		padding: 12rpx 0;
	}

	.load {
		width: 100%;
		height: 100rpx;
		float: left;
		text-align: center;
		line-height: 100rpx;
		font-size: 25rpx;
		color: #777777;
	}
</style>
